<!DOCTYPE html>
<html>
<body>
  <iframe id="player" style="width:80%;min-height:600px;" ></iframe>
  <script>
    var url = "https://www.youtube.com/embed/DjB1OvEYMhY?enablejsapi=1";
    document.getElementById("player").src = url;
    var player;

    function onYouTubeIframeAPIReady() {
      player = new YT.Player( 'player', {
        events: { 'onStateChange': onPlayerStateChange }
      });
    }
    function onPlayerStateChange(event) {
      if(event.data == 0){
          //khi video kết thúc
          alert("ended");
          //connect();
        }
      }
    </script>
    <script src="https://www.youtube.com/iframe_api"></script>
  </body>
  </html>